#include "SbotFocChart.h"
#include <QTime>

SbotFocChart::SbotFocChart()
{
    connect(&this->dataTestTimer, &QTimer::timeout, this, &SbotFocChart::flushDataTest);
    this->dataTestTimer.start(10); // 每秒钟生成一个数据点
}

void SbotFocChart::flushDataTest()
{
    static int cnt = 0;
    QVector<QVariant> dataArray;
    const double amplitude = 6.0;  // 振幅
    const double frequency = 1;  // 频率，调整此值以改变波形
    const double phase = 0;  // 相位，可以用来调整波形的起始点
    qint64 timestamp = QDateTime::currentDateTime().toMSecsSinceEpoch(); // 毫秒级时间戳

    dataArray.append(cnt++);
    double angleValue = 100;
    double alphaValue = amplitude * sin(2 * M_PI * frequency * timestamp / 1000.0 + phase) + amplitude;
    alphaValue = std::round(alphaValue * 100.0) / 100.0;
    double betaValue = amplitude * sin(2 * M_PI * frequency * timestamp / 1000.0 + phase + 4) + amplitude;
    betaValue = std::round(betaValue * 100.0) / 100.0;
    double aPhaseValue = amplitude * sin(2 * M_PI * frequency * timestamp / 1000.0 + phase) + amplitude;
    aPhaseValue = std::round(betaValue * 100.0) / 100.0;
    double bPhaseValue = amplitude * sin(2 * M_PI * frequency * timestamp / 1000.0 + phase + 2) + amplitude;
    bPhaseValue = std::round(betaValue * 100.0) / 100.0;
    double cPhaseValue = amplitude * sin(2 * M_PI * frequency * timestamp / 1000.0 + phase + 4) + amplitude;
    cPhaseValue = std::round(betaValue * 100.0) / 100.0;

    dataArray.append(angleValue);
    dataArray.append(alphaValue);
    dataArray.append(betaValue);
    dataArray.append(aPhaseValue);
    dataArray.append(bPhaseValue);
    dataArray.append(cPhaseValue);

    emit this->flushData(dataArray);
}
